package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.itboye.eweilisten.R;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by itboye on 2017/3/9.
 */

public class GridAdapter extends BaseAdapter {
    Context context;
    int selectedPosition;
    boolean iscchat;
    public Map<Integer, String> selected;

    public GridAdapter(Context context) {
        this.context = context;
        selected = new HashMap<Integer, String>();
    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void clearSelection(int position) {
        selectedPosition = position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHouder houder;
        if (convertView == null) {
            houder = new ViewHouder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gridview, null);
            houder.tvgridview = (TextView) convertView.findViewById(R.id.tvgridview);
            houder.textView3 = (CheckBox) convertView.findViewById(R.id.textView3);
            convertView.setTag(houder);
        } else {
            houder = (ViewHouder) convertView.getTag();
        }
        houder.textView3.setTag(position);
        if (selected.containsKey(position)) {

            houder.textView3.setChecked(true);
        } else {
            houder.textView3.setChecked(false);
        }

        houder.tvgridview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (iscchat) {
                    iscchat = false;
                } else {
                    iscchat = false;
                }
            }
        });
        return convertView;
    }

    public class ViewHouder {
        TextView tvgridview;
        CheckBox textView3;
    }
}

